//
//  LYFDetailsTableViewCell.m
//  段子手
//
//  Created by dllo on 16/3/18.
//  Copyright © 2016年 JokesTeam. All rights reserved.
//

#import "LYFDetailsTableViewCell.h"

@interface LYFDetailsTableViewCell ()

@property (nonatomic, retain) UIImageView *iconImg;/**< cell头像 */
@property (nonatomic, retain) UILabel *nameLabel;/**< 名字 */
@property (nonatomic, retain) UILabel *contentLabel;/**< 内容文字 */
@property (nonatomic, retain) UIImageView *bigImg;/**< 发表的图片 */
@property (nonatomic, retain) UIButton *upButton;/**< 赞图片 */
@property (nonatomic, retain) UILabel *upLabel;/**< 赞的人数 */
@property (nonatomic, retain) UIButton *downButton;/**< 不赞图片 */
@property (nonatomic, retain) UILabel *downLabel;/**< 不赞人数 */
@property (nonatomic, retain) UIButton *hotButton;/**< 评论图片 */
@property (nonatomic, retain) UILabel *hotLabel;/**< 评论人数 */
@property (nonatomic, retain) UIButton *forwardButton;/**< 转发图片 */
@property (nonatomic, retain) UILabel *forwardLabel;/**< 转发人数 */
@property (nonatomic, assign) BOOL isSelect;

@end

@implementation LYFDetailsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }return self;
}

- (void)dealloc {
    
}

- (void)setModel:(LYFDetailsModel *)model {
    _model = model;
    
    [_iconImg sd_setImageWithURL:[NSURL URLWithString:_model.avatar_url]];
    _iconImg.layer.cornerRadius = 20;
    _nameLabel.text = _model.name;
    _contentLabel.text = _model.text;
    [_bigImg sd_setImageWithURL:[NSURL URLWithString:_model.url]];
    _upLabel.text = _model.digg_count;
    _downLabel.text = _model.bury_count;
    _hotLabel.text = _model.comment_count;
    _forwardLabel.text = _model.share_count;
}

/** 创建那些破烂控件tmd */
- (void)createCell {
    self.iconImg = [[UIImageView alloc] init];
    [self.contentView addSubview:_iconImg];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    
    self.contentLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_contentLabel];
    
    
    self.bigImg = [[UIImageView alloc] init];
    [self.contentView addSubview:_bigImg];
    
    self.upButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_upButton];
    
    self.upLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_upLabel];
    
    self.downButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_downButton];
    
    self.downLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_downLabel];
    
    self.hotButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_hotButton];
    
    self.hotLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_hotLabel];
    
    self.forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_forwardButton];
    
    self.forwardLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_forwardLabel];
    
    _isSelect = NO;
}

/** 布局！ */
- (void)layoutSubviews {
    [super layoutSubviews];
    _iconImg.frame = CGRectMake(10, 10, 40, 40);
    _iconImg.backgroundColor = [UIColor orangeColor];
    _iconImg.layer.cornerRadius = 20;
    _iconImg.layer.masksToBounds = YES;/**< 图片圆角吻合 */
    
    NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], NSFontAttributeName, nil];
    CGRect rect = [_model.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:textDic context:nil];
    
    
    _nameLabel.frame = CGRectMake(70, 20, 150, 30);
//    _nameLabel.backgroundColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000];
    _nameLabel.textColor = [UIColor colorWithWhite:0.298 alpha:1.000];
    _nameLabel.font = [UIFont systemFontOfSize:15];
    
    _contentLabel.frame = CGRectMake(10, 70, SCREEN_WIDTH - 20, rect.size.height);
//    _contentLabel.backgroundColor = [UIColor colorWithRed:0.400 green:1.000 blue:0.800 alpha:1.000];
    _contentLabel.font = [UIFont systemFontOfSize:15];
    _contentLabel.numberOfLines = 0;
    
    _bigImg.frame = CGRectMake(10, 70 + rect.size.height + 10, SCREEN_WIDTH - 20, 200);
//    _bigImg.backgroundColor =/ [UIColor colorWithWhite:0.400 alpha:1.000];
    
    _upButton.frame = CGRectMake(0, 70 + rect.size.height + 10 + 200 + 10, 30, 30);
    [_upButton setImage:[UIImage imageNamed:@"RC32NLI__LBBJR]ET5I%D{5.png"] forState:UIControlStateNormal];
//    _upButton.frame = CGRectMake(0, 240, 30, 30);
//    [_upButton setImage:[UIImage imageNamed:@"RC32NLI__LBBJR]ET5I%D{5.jpg"] forState:UIControlStateNormal];
    [_upButton addTarget:self action:@selector(upButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _upLabel.frame = CGRectMake(40, 70 + rect.size.height + 10 + 200 + 10, 50, 30);
//    _upLabel.backgroundColor = [UIColor colorWithRed:0.502 green:0.251 blue:0.000 alpha:1.000];
    _upLabel.textColor = [UIColor colorWithWhite:0.298 alpha:1.000];
    _upLabel.font = [UIFont systemFontOfSize:15];
    
    _downButton.frame = CGRectMake(95, 70 + rect.size.height + 10 + 200 + 10, 30, 30);
    [_downButton setImage:[UIImage imageNamed:@"51FYKZ@K77SS}A0@{G_C]C7.png"] forState:UIControlStateNormal];
//    _downButton.frame = CGRectMake(95, 240, 30, 30);
//    [_downButton setImage:[UIImage imageNamed:@"51FYKZ@K77SS}A0@{G_C]C7.jpg"] forState:UIControlStateNormal];
    [_downButton addTarget:self action:@selector(downButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _downLabel.frame = CGRectMake(125, 70 + rect.size.height + 10 + 200 + 10, 50, 30);
//    _downLabel.backgroundColor = [UIColor colorWithRed:0.400 green:0.400 blue:1.000 alpha:1.000];
    _downLabel.textColor = [UIColor colorWithWhite:0.298 alpha:1.000];
    _downLabel.font = [UIFont systemFontOfSize:15];
    
    _hotButton.frame = CGRectMake(180, 70 + rect.size.height + 10 + 200 + 10, 30, 30);
    [_hotButton setImage:[UIImage imageNamed:@"LK@AF$6X){$X6E2WH3}5MUI.png"] forState:UIControlStateNormal];
//    _hotButton.frame = CGRectMake(180, 240, 30, 30);
//    [_hotButton setImage:[UIImage imageNamed:@"LK@AF$6X){$X6E2WH3}5MUI.jpg"] forState:UIControlStateNormal];
    [_hotButton addTarget:self action:@selector(hotButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _hotLabel.frame = CGRectMake(210, 70 + rect.size.height + 10 + 200 + 10, 50, 30);
//    _hotLabel.backgroundColor = [UIColor orangeColor];
    _hotLabel.textColor = [UIColor colorWithWhite:0.298 alpha:1.000];
    _hotLabel.font = [UIFont systemFontOfSize:15];
    
    _forwardButton.frame = CGRectMake(280, 70 + rect.size.height + 10 + 200 + 10, 30, 30);
    [_forwardButton setImage:[UIImage imageNamed:@"S7YX~39TSWAV2@[[WK19UXF.png"] forState:UIControlStateNormal];
//    _forwardButton.frame = CGRectMake(280, 240, 30, 30);
//    [_forwardButton setImage:[UIImage imageNamed:@"S7YX~39TSWAV2@[[WK19UXF.jpg"] forState:UIControlStateNormal];
    [_forwardButton addTarget:self action:@selector(forwardButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _forwardLabel.frame = CGRectMake(310, 70 + rect.size.height + 10 + 200 + 10, 50, 30);
//    _forwardLabel.backgroundColor = [UIColor colorWithRed:0.000 green:0.502 blue:0.502 alpha:1.000];
    _forwardLabel.textColor = [UIColor colorWithWhite:0.298 alpha:1.000];
    _forwardLabel.font = [UIFont systemFontOfSize:15];
    
}

/** 点赞方法 */
- (void)upButtonAction:(UIButton *) upButton {
    if (_isSelect == YES) {
        [_upButton setImage:[UIImage imageNamed:@"LSIJ7U8~XLPV(1HNCD9DYJO.png"] forState:UIControlStateNormal];
    } else {
        [_upButton setImage:[UIImage imageNamed:@"RC32NLI__LBBJR]ET5I%D{5.png"] forState:UIControlStateNormal];
    }
    _isSelect =!_isSelect;
}

/** 不攒方法 */
- (void)downButtonAction:(UIButton *) downButton {
    
    if (_isSelect == YES) {
        [_downButton setImage:[UIImage imageNamed:@"7Q5DXKBUXU`GULEZZ72B4XN.png"] forState:UIControlStateNormal];
    } else {
        [_downButton setImage:[UIImage imageNamed:@"51FYKZ@K77SS}A0@{G_C]C7.png"] forState:UIControlStateNormal];
    }
    
    _isSelect =!_isSelect;
    
}

/** 评论方法 */
- (void)hotButtonAction:(UIButton *) hotButton {
    
    [self.delegate pushComment:_model];
}

/** 转发方法 */
- (void)forwardButtonAction:(UIButton *) forwardButton {
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
